import _ from 'lodash'
export default class {
  // 发送验证码
  sendCode(data) {
    return this.request({
      url: '/admin/v1/admin_user/send_login_msg',
      method: 'POST',
      data
    })
  }

  phoneLogo(data) {
    return this.request({
      url: '/admin/v1/admin_user/get_token_msg',
      method: 'POST',
      data
    })
  }

  login(data) {
    return this.request({
      url: '/admin/v1/admin_user/get_token',
      method: 'POST',
      data
    })
  }
  getUserInfo() {
    return this.request({
      url: '/api/admin/admininfo/',
      method: 'GET'
    })
  }

  getRefreshToken() {
    return this.request({
      url: '/admin/v1/user/refresh_token',
      method: 'GET'
    })
  }

  // 富文本图片上传 》已废弃
  pushImg(data) {
    return this.request({
      url: '/summernote/upload_attachment/',
      method: 'POST',
      data,
      transformResponse: [
        (data) => {
          const location = _.get(JSON.parse(data), 'files.0.url', '')
          return {
            code: 0,
            location
          }
        }
      ]
    })
  }
  // 富文本文件上传
  // pushRichFile(data) {
  //   return this.request({
  //     url: `/api/admin/upload/`,
  //     method: "POST",
  //     data,
  //   });
  // }

  // 富文本文件上传
  pushRichFile(data) {
    return this.request({
      url: `https://files.meta-720.com/upload/v1/`,
      method: 'POST',
      data
    })
  }

  // 多图片上传
  pushMultipleImg(data) {
    return this.request({
      url: `/api/admin/venue_img/`,
      method: 'POST',
      data
    })
  }

  // #region 用户管理
  getUserList(params) {
    return this.request({
      url: '/api/admin/user/',
      method: 'GET',
      params
    })
  }
  addUser(data) {
    return this.request({
      url: `/api/admin/user/`,
      method: 'POST',
      data
    })
  }
  editUser(id, data) {
    return this.request({
      url: `/api/admin/user/${id}/`,
      method: 'PUT',
      data
    })
  }
  delUser(id) {
    return this.request({
      url: `/api/admin/user/${id}/`,
      method: 'DELETE'
    })
  }
  // #endregion
  // #region 管理员管理

  getAdminResource() {
    return this.request({
      url: `/admin/v1/admin_user/self/resource`,
      method: 'GET'
    })
  }

  getAdminList(params) {
    return this.request({
      url: '/admin/v1/admin_user/list',
      method: 'GET',
      params
    })
  }
  getAdminDetail(id) {
    return this.request({
      url: `/admin/v1/admin_user?id=${id}`,
      method: 'GET'
    })
  }
  addAdmin(data) {
    return this.request({
      url: `/admin/v1/admin_user`,
      method: 'PUT',
      data
    })
  }
  editAdmin(id, data) {
    return this.request({
      url: `/admin/v1/admin_user?id=${id}`,
      method: 'POST',
      data
    })
  }
  delAdmin(id) {
    return this.request({
      url: `/admin/v1/admin_user?id=${id}`,
      method: 'DELETE'
    })
  }

  getAdminRole(id) {
    return this.request({
      url: `/admin/v1/admin_user/role?id=${id}`,
      method: 'GET'
    })
  }
  setRole(id, data) {
    return this.request({
      url: `/admin/v1/admin_user/role?id=${id}`,
      method: 'POST',
      data
    })
  }
  // #endregion
  // #region 角色管理
  getRoleList(params) {
    return this.request({
      url: '/admin/v1/role/list',
      method: 'GET',
      params
    })
  }
  getRoleDetail(id) {
    return this.request({
      url: `/admin/v1/role?id=${id}`,
      method: 'GET'
    })
  }

  addRole(data) {
    return this.request({
      url: `/api/admin/role`,
      method: 'PUT',
      data
    })
  }

  editRole(id, data) {
    return this.request({
      url: `/admin/v1/role?id=${id}`,
      method: 'POST',
      data
    })
  }

  delRole(id) {
    return this.request({
      url: `/admin/v1/role?id=${id}`,
      method: 'DELETE'
    })
  }

  getRolePermission(id) {
    return this.request({
      url: `/admin/v1/role/resource?id=${id}`,
      method: 'GET'
    })
  }

  editRolePermission(id, data) {
    return this.request({
      url: `/admin/v1/role/resource?id=${id}`,
      method: 'POST',
      data
    })
  }
  // #endregion

  // #region 角色管理
  // 权限列表
  getPermissionList(params) {
    return this.request({
      url: '/admin/v1/resource/list',
      method: 'GET',
      params
    })
  }

  // 删除权限
  deletePermission(id) {
    return this.request({
      url: `/admin/v1/resource?id=${id}`,
      method: 'DELETE'
    })
  }

  // 权限详情
  permissionDetail(id) {
    return this.request({
      url: `/admin/v1/resource?id=${id}`,
      method: 'GET'
    })
  }

  // 添加权限
  addPermission(data) {
    return this.request({
      url: `/admin/v1/resource`,
      method: 'PUT',
      data
    })
  }

  // 编辑权限
  editPermission(id, data) {
    return this.request({
      url: `/admin/v1/resource?id=${id}`,
      method: 'POST',
      data
    })
  }
  // #endregion
}
